import request from '@/utils/request'

// 结算页面生成订单 根据购物车
export const createOrder = () => {
  return request('/member/order/pre', 'get')
}

// 再次购买，根据订单id生成订单
export const findOrderRepurchase = (id) => {
  return request(`/member/order/repurchase/${id}`, 'get')
}

// 添加收货地址
export const addAddress = (from) => {
  return request('/member/address', 'post', from)
}

// 修改收货地址
export const editAddress = (from) => {
  return request(`/member/address/${from.id}`, 'put', from)
}

// 提交订单 获取订单Id
export const submitOrder = (params) => {
  return request('/member/order', 'post', params)
}

// 根据订单Id，获取数据
export const findOrderDetail = (orderId) => {
  return request(`/member/order/${orderId}`, 'get')
}

// 我的订单
export const findOrderList = ({ page = 1, pageSize = 10, orderState = 0 }) => {
  return request('/member/order', 'get', { page, pageSize, orderState })
}

// 取消订单
export const cancelOrder = (orderId, cancelReason) => {
  return request(`/member/order/${orderId}/cancel`, 'put', { cancelReason })
}

// 删除订单
export const delteOrder = (orderId) => {
  return request('/member/order', 'delete', { ids: [orderId] })
}

// 确认收货
export const confirmOrder = (orderId) => {
  return request(`/member/order/${orderId}/receipt`, 'put')
}

// 查看物流
export const logisticsOrder = (id) => {
  return request(`/member/order/${id}/logistics`, 'get')
}
